
public class Person {
	int x, y; 
	int size;
	int index;

	public Person(int x, int y, int size, int index) {
	    this.x = x; 
	    this.y = y;
	    this.size=size;
	    this.index = index;
	 } 
    public void move(Directions direction){
    	this.x += direction.getX();
        this.y += direction.getY(); 		
    } 
    
    public boolean checkAvailability(int step, int[][] map, Directions direction){
    	if(checkBound(step,map,direction)&&checkSquareExist(step,map,direction)) return true;
    	else return false;
    }
    
    private boolean checkBound(int step, int[][] map, Directions direction){
    	int xBound = map.length;
		int yBound = map[0].length;
		int option = direction.ordinal();
    	switch(option){
    	case 0:
    		if(y >= step) return true;
    		break;
    	case 1:
    		if(x + size < xBound - step) return true;
    		break;
    	case 2:
    		if(y + size < yBound - step) return true;
    		break;
    	case 3:
    		if(x >= step) return true;
    		break;
    	case 4:
    		if((x>=step)&&(y>=step)) return true;
    		break;
    	case 5:
    		if((x+size<xBound-step)&&(y>=step)) return true;
    		break;
    	case 6:
    		if((x+size<xBound-step)&&(y+size<yBound-step)) return true;
    		break;
    	case 7:
    		if((x>=step)&&(y+size<yBound-step)) return true;
    		break;
    	}
    	return false;
    }
    private boolean checkSquareExist(int step, int[][] map, Directions direction){
    	int dx=x, dy=y;
    	int option = direction.ordinal();
    	switch(option){
	    	case 0: dy-=step; break;
	    	case 1: dx+=step; break;
	    	case 2: dy+=step; break;
	    	case 3: dx-=step; break;
	    	case 4: dx-=step; dy-=step; break;
	    	case 5: dx+=step; dy-=step; break;
	    	case 6: dx+=step; dy+=step; break;
	    	case 7: dx-=step; dy+=step; break;
    	}
    	for(int d=0;d<size;d++){
			if(map[dx+d][dy+d]==0) return false;
		}
		for(int d=0;d<size;d++){
			if(map[dx+size-1-d][dy+d]==0) return false;
		}
		for(int i=0;i<size;i++){
			for(int j=0;j<size;j++){
				if(map[dx+i][dy+j]==0) return false;
			}
		}
		return true;
    	
    }
    
}
